txtseg1 = '''#!/usr/bin/python
# GalacticModel.py

# Library modules
from time import asctime
from os import linesep
#import numpy

# Intake parameters
# Units/types noted are the FINAL units/types, after run through alterpars.

'''







txtseg2 = '''

for i in extpars:
    cmd = "%s = extpars['%s']" % (i,i)
    exec cmd


# SIMULATION PARAMETERS
import GM_simulationparameters as spars
simpars = {# Parameters directly set by user
           'nodes' : spars.nodes,
           'subnodes' : spars.subnodes,
           'codedir' : spars.codedir,
           'outdir' : spars.outdir,
           'pydir' : spars.pydir,
           #'Nptsxy' : spars.Nptsxy, # int
           'scale' : spars.scale, # pc float
           'galactocentric' : spars.galactocentric, # Not yet implemented
           'LensedMag' : spars.LensedMag, # float # Not yet implemented
           'SourceMag' : spars.SourceMag, # float
           'Magnification' : spars.Magnification, # float # Not yet implemented
           'brightlimit' : spars.brightlimit, # int
           'lres' : spars.lres,
           'bres' : spars.bres,
           'dres' : spars.dres,
           'band' : spars.band,
           'c0_V' : spars.c0_V,
           'rho0_V' : spars.rho0_V,
           'c0_I' : spars.c0_I,
           'rho0_I' : spars.rho0_I,
           'c0' : '',
           'rho0' : '',
           'fitcrho' : spars.fitcrho,
           'fixedrho' : spars.fixedrho,
           'fixedc' : spars.fixedc,
           'latitudeweight' : spars.latitudeweight,
           'latitudeweightexternal' : '',
           'latitudeweightinternal' : '',
           'interpolateMv' : spars.interpolateMv,
           'intervals' : spars.intervals,
           'ApparentLimits' : spars.ApparentLimits,
           'interpolateMass' : spars.interpolateMass,
           'maxmassinterval' : spars.maxmassinterval,
           # Derived parameters
           'ScaleZ' : '', # float pc
           'dlocs' : '', # float index-like array
           'llocs' : '', # float index-like array
           'blocs' : '', # float index-like array
           'delds' : '',
           'dells' : '',
           'delbs' : '',
           'delMvs' : '', #### Not supported yet
           'delMs' : '', #### Not supported yet
           'Nptsdlb' : '', # int
           'PtScaled' : '', # float pc
           'PtScalela' : '', # float radians
           'PtScaleba' : '', # float radians
#           '' : spars.,
#           '' : '',
           }

# PHYSICAL PARAMETERS
import GM_physicalparameters as ppars
phypars = {# From Han
           'R0' : ppars.R0, # pc float
           'hR' : ppars.hR, # pc float
           'hdz' : ppars.hdz, # pc float
           'ScaleList' : ppars.ScaleList, # pc float array
           'bulk_vels' : ppars.bulk_vels, #pc/yr float array
           'sigma_vels' : ppars.sigma_vels, #pc/yr float array
           # Derived parameters, Han
           'vanillaScaleList' : '',
           'modifiedScaleList' : '',
           # Binney & Merrifield 1998
           # The luminosity function
           'MvList' : ppars.MvList, # mags array
           'LumFuncList' : ppars.LumFuncList, # stars pc^-3 mags^-1 float array
           # Derived parameters, B & M
           'delMvList' : '',
           'vanillaMvList' : '',
           'vanillaLumFuncList' : '',
           'vanilladelMvList' : '',
           'modifiedMvList' : '',
           'modifiedLumFuncList' : '',
           'modifieddelMvList' : '',
           # Cox 1999
           # The measured angular density of stars
           'bvals' : ppars.bvals, # degrees array
           'MvVals' : ppars.MvVals, # mags array
           'N_bM_V' : ppars.N_bM_V, # float array log10(stars mag**-1 deg**-2)
           'allsky_V' : ppars.allsky_V, # float array log10(stars mag**-1 deg**-2)
           'N_bM_I' : ppars.N_bM_I, # float array log10(stars mag**-1 deg**-2)
           'allsky_I' : ppars.allsky_I, # float array log10(stars mag**-1 deg**-2)
           'N_bM' : '', # float array log10(stars mag**-1 degree**-2)
           'allsky' : '', # float array log10(stars mag**-1 degree**-2)
            # Derived parameters, Cox
           'limitset' : '', # float mags array
           'delMvVals' : '', # float mags array
           'vanillaMvVals' : '', # float mags array
           'vanillalimitset' : '', # float mags array
           'vanilladelMvVals' : '', # float mags array
           'fittingMvVals' : '', # mags array
           'fittinglimitset' : '', # float mags array
           'fittingdelMvVals' : '', # float mags array
           'modifiedMvVals' : '', # float mags array
           'modifiedlimitset' : '', # float mags array
           'modifieddelMvVals' : '', # float mags array
           # Kroupa et al. 1993
           # The mass function
           'masslimits' : ppars.masslimits, # 2d Msun float array
           'massindices' : ppars.massindices, # 1d unitless float array
           'massmults' : ppars.massmults, # 1d float array
           'MvMass' : ppars.MvMass,
           # Derived parameters, Kroupa
           'delMvMass' : '',
           'limitsMvMass' : '',
           'vanillaMvMass' : '', 
           'vanilladelMvMass' : '',
           'vanillalimitsMvMass' : '',
           'modifiedMvMass' : '',
           'modifieddelMvMass' : '',
           'modifiedlimitsMvMass' : '',
           # Derived parameters, Han + Kroupa
           'MvMassScales' : '',
           'modifiedMvMassScales' : '',
           'vanillaMvMassScales' : '',
#           '' : ppars.,
#           '' : '',
           }


# Homemade modules
import GM_alterpars # OK
#import GM_nonlinear
import GM_distinction # OK
import plot_distinction # OK
import GM_LumFunc # OK
import plot_LumFunc # OK
import GM_fitc0rho0 # OK
# These modules are all secretly used by GM_fitc0rho0
#import GM_apparent # OK
#import GM_logN # OK
#import GM_N_bvals # OK
# Plot the aftermath, then delete the unloved
import plot_fitc0rho0 # OK
import plot_apparent # OK
import plot_logN # OK
import replot_logN
import plot_logN_HanStyle # OK

import GM_darklight
# Secretly used by GM_darklight and GM_MassDistrib and, well, lots of things
#import GM_InterpRoutines
import plot_darklight
import GM_MassDistrib # OK?
import plot_MassDistrib # OK?

import GM_velocities # OK?
import plot_velocities # OK?
import GM_EstimateDependence
import plot_EstimateDependence
import GM_SimpleIntegrate # OK?
import plot_SimpleIntegrate # OK?


# Begin
print 'Beginning.'
print asctime()
print linesep

# Update parameters so that their units and datatypes are appropriate
(simpars, phypars) = GM_alterpars.alterpars(simpars, phypars)
del GM_alterpars
#simpars = GM_nonlinear.nonlinear(simpars)
#del GM_nonlinear

# Determine distance modulus and extinction for all locations
# DistMod is 1d (d only); ExtMod is 2d (d, b)
(DistMod, ExtMod) = GM_distinction.distinction(simpars, phypars)
del GM_distinction
# Plot a slice through that
#plot_distinction.plot(DistMod, ExtMod, simpars)
del plot_distinction
print 'I have calculated the extinction coefficient and distance modulus.'
print asctime()
print linesep

# Get distribution of stars
# elements of distriblist are 3d (d, l, b)
distriblist = GM_LumFunc.lumfunc(simpars, phypars)
del GM_LumFunc
# Plot a slice through that
#plot_LumFunc.plot(distriblist, simpars)
del plot_LumFunc
print 'I have calculated the distribution of stars.'
print asctime()
print linesep

for i in range(0,rho_n):
    simpars['rho0'] = rho_min + i*rho_space/rho_n
    for j in range(0,c_n):
        simpars['c0'] = c_min + j*c_space/c_n
        

        # Calculate everything for chosen rho0 and c0
        (appearance, N, allskyN, compN) = GM_fitc0rho0.iterateverbose(simpars, phypars, DistMod, ExtMod, distriblist)
        #...and throw a Han-style comparison in for good measure
        plot_logN_HanStyle.plot(simpars, phypars, compN, N, allskyN)
    print "I've looped over a set of", c_n, "and my index is", codeindex



print "Code segment", codeindex, "reporting completion!"
print asctime()
print linesep'''

